package com.future.bantang.adapter;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 16-1-11.
 */
public abstract class BaseAdapter<T> extends android.widget.BaseAdapter {
    protected List<T> mList;
    protected Context context;
    private String TAG="BaseAdapter";

    public BaseAdapter(Context context) {
        this.context = context;
        mList=new ArrayList<>();
    }

    /**
     * 设置数据
     * @param list
     */
    public void setDatas(List<T> list){
        this.mList=list;
        this.notifyDataSetChanged();
    }

    /**
     * 添加数据
     * @param list
     */
    public void addDatas(List<T> list){
        this.mList.addAll(list);
        this.notifyDataSetChanged();
    }

    /**
     * 清理数据
     */
    public void clearDatas(){
        this.mList.clear();
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public T getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
